#include <iostream>
#include <cstdint>

// 假设这是日志输出宏
#define HCCL_ERROR(fmt, ...) std::printf(fmt, ##__VA_ARGS__)

// 假设 SYS_MAX_COUNT 是一个预定义的常量
#define SYS_MAX_COUNT 100

// 假设 CHK_RET 是一个错误检查宏
#define CHK_RET(func) \
    do { \
        HcclResult ret = func; \
        if (ret != HCCL_SUCCESS) { \
            std::cerr << "Function call failed with error code: " << ret << std::endl; \
            return ret; \
        } \
    } while (0)

// 定义 HCCL_CHECK 宏
#define HCCL_CHECK(func) \
    do { \
        HcclResult ret = func; \
        if (ret != HCCL_SUCCESS) { \
            std::cerr << "HCCL_CHECK failed with error code: " << ret << std::endl; \
            return ret; \
        } \
    } while (0)

// 定义 HcclResult 枚举类型
typedef enum {
    HCCL_SUCCESS = 0, /**< success */
    HCCL_E_PARA = 1,
} HcclResult;

// 假设 u64 是 uint64_t 的别名
typedef uint64_t u64;

// 假设 configHandle 是一个自定义类型，这里简单用 int 表示
typedef int ConfigHandle;

// 假设 HCOM_ERROR_CODE 是一个宏
#define HCOM_ERROR_CODE(err) (err)

// 模拟 CheckMagicWord 函数
HcclResult CheckMagicWord(ConfigHandle configHandle) {
    // 这里简单假设当 configHandle 为负数时返回错误
    if (configHandle < 0) {
        HCCL_ERROR("[Check][MagicWord]errNo[0x%016llx] Magic word is invalid", HCOM_ERROR_CODE(HCCL_E_PARA));
        return HCCL_E_PARA;
    }
    return HCCL_SUCCESS;
}

// HcomCheckCount 函数
HcclResult HcomCheckCount(const u64 count) {
    if (count > SYS_MAX_COUNT) {
        HCCL_ERROR("[Check][Count]errNo[0x%016llx] count[%llu] is invalid(bigger than MAX count[%llu])",
                   HCOM_ERROR_CODE(HCCL_E_PARA), count, SYS_MAX_COUNT);
        return HCCL_E_PARA;
    }
    return HCCL_SUCCESS;
}

int main() {
    // 测试 HcomCheckCount 函数
    u64 validCount = 50;
    HcclResult result = HcomCheckCount(validCount);
    if (result == HCCL_SUCCESS) {
        std::cout << "HcomCheckCount passed for valid count." << std::endl;
    } else {
        std::cerr << "HcomCheckCount failed with error code: " << result << std::endl;
    }

    u64 invalidCount = 150;
    // 使用 HCCL_CHECK 宏进行检查
    HCCL_CHECK(HcomCheckCount(invalidCount));

    // 测试 CheckMagicWord 函数
    ConfigHandle validConfig = 1;
    CHK_RET(CheckMagicWord(validConfig));
    std::cout << "CheckMagicWord passed for valid config." << std::endl;

    ConfigHandle invalidConfig = -1;
    result = CheckMagicWord(invalidConfig);
    if (result == HCCL_SUCCESS) {
        std::cout << "CheckMagicWord passed for invalid config (should not happen)." << std::endl;
    } else {
        std::cerr << "CheckMagicWord failed with error code: " << result << std::endl;
    }

    return 0;
}
